package com.zcj.test.gallery;

import java.lang.ref.WeakReference;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

public class AsyncTaskManager {

    private static final String TAG = "AsyncTaskManager";
    private static AsyncTaskManager manager;
    private ThreadPoolExecutor threadPoolExecutor;
    static {
        manager = new AsyncTaskManager();
    }

    public static AsyncTaskManager getManager() {
        return manager;
    }

    public AsyncTaskManager() {
        this.threadPoolExecutor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
    }

    public void start(Runnable runnable) {
        Future<?> request = threadPoolExecutor.submit(runnable);
        new WeakReference<Future<?>>(request);

    }
    
    public void stop(Runnable runnable) {
        threadPoolExecutor.shutdown();
    }

//    public boolean stop() {
////       BlockingQueue<Runnable> tasks =  threadPoolExecutor.getQueue();
////        for (Runnable node: tasks){
////            threadPoolExecutor.remove(node);
////        }
////        if (threadPoolExecutor.getQueue()==null) {
////            return true;
////        }
//        return false;
//    }


}
